package interfaz;

import org.uqbar.arena.actions.MessageSend;
import org.uqbar.arena.layout.ColumnLayout;
import org.uqbar.arena.widgets.Button;
import org.uqbar.arena.widgets.Label;
import org.uqbar.arena.widgets.Panel;
import org.uqbar.arena.widgets.TextBox;
import org.uqbar.arena.windows.Dialog;
import org.uqbar.arena.windows.WindowOwner;
import org.uqbar.commons.model.UserException;

import tablero.Coordenada;
import tablero.Personaje;
import tablero.Tablero;

public class CrearPersonajeDialog extends Dialog<Personaje> {
	Tablero currentMapa;

	public CrearPersonajeDialog(WindowOwner owner, Personaje model,
			Tablero mapa, Coordenada coordenada) {
		super(owner, model);
		currentMapa = mapa;

	}

	@Override
	protected void createMainTemplate(Panel mainPanel) {
		this.setTitle("Creación del personaje");
		super.createMainTemplate(mainPanel);
	}

	@Override
	protected void createFormPanel(Panel mainPanel) {

		Panel form = new Panel(mainPanel);
		form.setLayout(new ColumnLayout(2));

		new Label(form).setText("Nombre");
		new TextBox(form).bindValueToProperty("nombre");

		new Label(form).setText("Ubicación");
		TextBox tx = new TextBox(form);
		tx.bindValueToProperty("coordenada").setAdapter(new CoodenadaAdapter());

		new Label(form).setText("MovimientosPosibles");
		new TextBox(form).bindValueToProperty("moveMax").setAdapter(
				new CantidadMovimientosPosiblesAdapter());

	}

	@Override
	protected void addActions(Panel actions) {
		new Button(actions).setCaption("Aceptar")
				.onClick(new MessageSend(this, ACCEPT)).setAsDefault()
				.disableOnError();

		new Button(actions).setCaption("Cancelar").onClick(
				new MessageSend(this, CANCEL));
	}

	@Override
	protected void executeTask() {
		this.currentMapa.agregarPersonaje(this.getModel());
	}
}
